/*    */ package com.cr.framework.interceptor.impl;
/*    */ 
/*    */ import com.cr.common.json.JSON;
/*    */ import com.cr.framework.interceptor.RepeatSubmitInterceptor;
/*    */ import java.util.HashMap;
/*    */ import java.util.Map;
/*    */ import javax.servlet.http.HttpServletRequest;
/*    */ import javax.servlet.http.HttpSession;
/*    */ import org.springframework.stereotype.Component;
/*    */ 
/*    */ @Component
/*    */ public class SameUrlDataInterceptor extends RepeatSubmitInterceptor {
/* 20 */   public final String REPEAT_PARAMS = "repeatParams";
/*    */   
/* 22 */   public final String REPEAT_TIME = "repeatTime";
/*    */   
/* 24 */   public final String SESSION_REPEAT_KEY = "repeatData";
/*    */   
/* 31 */   private int intervalTime = 10;
/*    */   
/*    */   public void setIntervalTime(int intervalTime) {
/* 35 */     this.intervalTime = intervalTime;
/*    */   }
/*    */   
/*    */   public boolean isRepeatSubmit(HttpServletRequest request) throws Exception {
/* 43 */     String nowParams = JSON.marshal(request.getParameterMap());
/* 44 */     Map<String, Object> nowDataMap = new HashMap<>();
/* 45 */     nowDataMap.put("repeatParams", nowParams);
/* 46 */     nowDataMap.put("repeatTime", Long.valueOf(System.currentTimeMillis()));
/* 49 */     String url = request.getRequestURI();
/* 51 */     HttpSession session = request.getSession();
/* 52 */     Object sessionObj = session.getAttribute("repeatData");
/* 53 */     if (sessionObj != null) {
/* 55 */       Map<String, Object> map = (Map<String, Object>)sessionObj;
/* 56 */       if (map.containsKey(url)) {
/* 58 */         Map<String, Object> preDataMap = (Map<String, Object>)map.get(url);
/* 59 */         if (compareParams(nowDataMap, preDataMap) && compareTime(nowDataMap, preDataMap))
/* 61 */           return true; 
/*    */       } 
/*    */     } 
/* 65 */     Map<String, Object> sessionMap = new HashMap<>();
/* 66 */     sessionMap.put(url, nowDataMap);
/* 67 */     session.setAttribute("repeatData", sessionMap);
/* 68 */     return false;
/*    */   }
/*    */   
/*    */   private boolean compareParams(Map<String, Object> nowMap, Map<String, Object> preMap) {
/* 76 */     String nowParams = (String)nowMap.get("repeatParams");
/* 77 */     String preParams = (String)preMap.get("repeatParams");
/* 78 */     return nowParams.equals(preParams);
/*    */   }
/*    */   
/*    */   private boolean compareTime(Map<String, Object> nowMap, Map<String, Object> preMap) {
/* 86 */     long time1 = ((Long)nowMap.get("repeatTime")).longValue();
/* 87 */     long time2 = ((Long)preMap.get("repeatTime")).longValue();
/* 88 */     if (time1 - time2 < (this.intervalTime * 1000))
/* 90 */       return true; 
/* 92 */     return false;
/*    */   }
/*    */ }


/* Location:              D:\tmp\creditorRights-admin\BOOT-INF\lib\creditorRights-framework-4.7.0.jar!\com\cr\framework\interceptor\impl\SameUrlDataInterceptor.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */